package com.example.foreapp;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class AddActivity extends Activity implements OnClickListener{
	
	private EditText classname_et;
	private Button btn_add;
	private DbOpenHelper db;
	private EditText pkg_et;
	
 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_favor);
		classname_et=(EditText) findViewById(R.id.classname);
		btn_add=(Button) findViewById(R.id.btn_add);
		pkg_et=(EditText)findViewById(R.id.pkgname);
		db=DbUtil.getIns(this);
		btn_add.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		String cname=classname_et.getEditableText().toString();
		String packname=pkg_et.getEditableText().toString();
		if(cname!=null&&cname.trim().length()!=0){
			SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmss");
			String pname=cname.substring(0,cname.lastIndexOf("."));
			String classname=cname.substring(cname.lastIndexOf(".")+1, cname.length());
			ActivityInfo info=new ActivityInfo();
			info.setClassName(classname.trim());
			if(packname!=null&&packname.trim().length()>0){
				info.setPkgName(packname.trim());
			}else{
				info.setPkgName(pname);
			}
			info.setTime(sdf.format(new Date()));
			info.setFavor(true);
			db.insertRcode(info.getTime(), info.getLabel(), info.getPkgName(), info.getClassName());
			long count=db.updateRecode(info);
			Log.d("AddActivity", "count:"+count);
			classname_et.setText("");
			pkg_et.setText("");
		}
	}
	
	
}
